package RPC;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.UnknownHostException;

import BasicDataType.CookieType;
import BasicDataType.IPP;
import cs5300.SessionTable;
import cs5300.sessionState;

public class RPCserverTest {

	@Test
	public void testRun() {
		try {

			RPCserver rpcs1 = new RPCserver(5200);
			Thread t = new Thread(rpcs1);
			t.start();

			RPCserver rpcs2 = new RPCserver(5300);
			Thread t2 = new Thread(rpcs2);
			t2.start();

			IPP testServer = new IPP();
			testServer.IPaddress = InetAddress.getByName("localhost");
			testServer.Port = 5200;

			IPP testServer2 = new IPP();
			testServer2.IPaddress = InetAddress.getByName("localhost");
			testServer2.Port = 5300;
			RPCclient.desList.add(testServer);
			RPCclient.desList.add(testServer2);
			RPCclient testclient = new RPCclient();
			SessionTable st = SessionTable.getInstance();
			sessionState sState = new sessionState();
			sState.cookie = new CookieType(rpcs1.serverAddress);
			sState.cookie.ippPrimary = rpcs1.serverAddress;
			testclient.sessionWrite(sState);
			DatagramPacket dp = testclient.sessionRead(sState.cookie);
			String temp = new String(dp.getData());
			ResponseMessage resM = new ResponseMessage(temp);
			sessionState state = new sessionState();
			state = sessionState.getSessionState(resM.result);
			System.out.println(state.getString());
			String hello = sState.getString();
			System.out.println(hello);
			// assertEquals(resM.result,(sState.getString()));

		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
